package com.wiiss.system.controller;

import com.wiiss.common.annotation.Log;
import com.wiiss.common.controller.BaseController;
import com.wiiss.common.domain.AjaxResult;
import com.wiiss.common.domain.page.TableDataInfo;
import com.wiiss.common.enums.BusinessType;
import com.wiiss.common.utils.poi.ExcelUtil;
import com.wiiss.system.domain.SystemOrignConfig;
import com.wiiss.system.service.ISystemOrignConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 第三方接口配置Controller
 *
 * @author my
 * @date 2022-01-06
 */
@Api(tags = "第三方接口配置")
@RestController
@RequestMapping("/mcs/config")
public class SystemOrignConfigController extends BaseController {

    @Autowired
    private ISystemOrignConfigService systemOrignConfigService;

    /**
     * 查询第三方接口配置列表
     */
    @ApiOperation("查询第三方接口配置列表")
    @ApiImplicitParam(name = "list", value = "查询第三方接口配置列表", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(SystemOrignConfig systemConfig) {
        startPage();
        List<SystemOrignConfig> list = systemOrignConfigService.selectSystemConfigList(systemConfig);
        return getDataTable(list);
    }

    /**
     * 导出第三方接口配置列表
     */
    @ApiOperation("导出第三方接口配置列表")
    @ApiImplicitParam(name = "export", value = "导出第三方接口配置列表", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:export')")
    @Log(title = "第三方接口配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SystemOrignConfig systemConfig) {
        List<SystemOrignConfig> list = systemOrignConfigService.selectSystemConfigList(systemConfig);
        ExcelUtil<SystemOrignConfig> util = new ExcelUtil<SystemOrignConfig>(SystemOrignConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 获取第三方接口配置详细信息
     */
    @ApiOperation("获取第三方接口配置详细信息")
    @ApiImplicitParam(name = "getInfo", value = "获取第三方接口配置详细信息", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(systemOrignConfigService.selectSystemConfigById(id));
    }

    /**
     * 新增第三方接口配置
     */
    @ApiOperation("新增第三方接口配置")
    @ApiImplicitParam(name = "add", value = "新增第三方接口配置", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:add')")
    @Log(title = "第三方接口配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemOrignConfig systemConfig) {
        return toAjax(systemOrignConfigService.insertSystemConfig(systemConfig));
    }

    /**
     * 修改第三方接口配置
     */
    @ApiOperation("修改第三方接口配置")
    @ApiImplicitParam(name = "edit", value = "修改第三方接口配置", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:edit')")
    @Log(title = "第三方接口配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemOrignConfig systemConfig) {
        return toAjax(systemOrignConfigService.updateSystemConfig(systemConfig));
    }

    /**
     * 删除第三方接口配置
     */
    @ApiOperation("删除第三方接口配置")
    @ApiImplicitParam(name = "remove", value = "删除第三方接口配置", dataType = "SystemConfig")
    @PreAuthorize("@ss.hasPermi('mcs:config:remove')")
    @Log(title = "第三方接口配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(systemOrignConfigService.deleteSystemConfigByIds(ids));
    }
}
